<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>分布式事务：构建可靠的分布式系统基石</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            transition: all 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .feature-icon {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: -0.2rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #f5f7fa 0%, #e9ecef 100%);
            border-left: 4px solid #667eea;
            padding: 1.5rem;
            margin: 1.5rem 0;
            border-radius: 0 8px 8px 0;
        }
        
        .solution-card {
            background: white;
            border-radius: 12px;
            padding: 2rem;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
            transition: all 0.3s ease;
            border: 1px solid #e5e7eb;
        }
        
        .solution-card:hover {
            transform: translateY(-4px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            border-color: #667eea;
        }
        
        .pros-cons {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 1rem;
            margin-top: 1rem;
        }
        
        .pros, .cons {
            padding: 1rem;
            border-radius: 8px;
        }
        
        .pros {
            background: #f0fdf4;
            border: 1px solid #86efac;
        }
        
        .cons {
            background: #fef2f2;
            border: 1px solid #fca5a5;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 leading-tight">
                    分布式事务
                </h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90">
                    构建可靠的分布式系统基石
                </p>
                <div class="flex justify-center space-x-8 text-lg">
                    <div class="flex items-center">
                        <i class="fas fa-network-wired mr-2"></i>
                        <span>跨服务协调</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-shield-alt mr-2"></i>
                        <span>数据一致性</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-sync-alt mr-2"></i>
                        <span>容错机制</span>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-12 max-w-6xl">
        <!-- Introduction -->
        <div class="content-card rounded-xl shadow-xl p-8 mb-8">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">分</span>布式事务是指在分布式系统中，对跨多个服务或数据库的数据操作进行的一致性保证。与传统的单机事务不同，分布式事务涉及多个独立的服务或数据存储系统，这些系统可能在不同的物理或网络环境中。分布式事务的关键挑战在于确保所有参与的系统在事务完成后都处于一致的状态，即所有操作要么全部成功，要么全部失败，避免出现部分成功部分失败的情况。
            </p>
        </div>

        <!-- ACID Properties -->
        <section class="mb-12">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">
                <i class="fas fa-cube feature-icon mr-3"></i>分布式事务的基本概念
            </h2>
            
            <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                <div class="content-card rounded-lg p-6">
                    <div class="flex items-center mb-4">
                        <div class="w-12 h-12 bg-purple-100 rounded-lg flex items-center justify-center mr-4">
                            <i class="fas fa-atom text-purple-600 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-gray-800">原子性（Atomicity）</h3>
                    </div>
                    <p class="text-gray-600">确保事务中的所有操作要么全部成功，要么全部失败。即使事务涉及多个服务或数据库，操作也应该像单一事务那样具有原子性。</p>
                </div>
                
                <div class="content-card rounded-lg p-6">
                    <div class="flex items-center mb-4">
                        <div class="w-12 h-12 bg-blue-100 rounded-lg flex items-center justify-center mr-4">
                            <i class="fas fa-check-circle text-blue-600 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-gray-800">一致性（Consistency）</h3>
                    </div>
                    <p class="text-gray-600">事务完成后，所有参与的服务或数据库应该处于一致的状态，确保数据的完整性和正确性。</p>
                </div>
                
                <div class="content-card rounded-lg p-6">
                    <div class="flex items-center mb-4">
                        <div class="w-12 h-12 bg-green-100 rounded-lg flex items-center justify-center mr-4">
                            <i class="fas fa-lock text-green-600 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-gray-800">隔离性（Isolation）</h3>
                    </div>
                    <p class="text-gray-600">事务的执行不应受到其他并发事务的影响，每个事务的操作应该是隔离的。</p>
                </div>
                
                <div class="content-card rounded-lg p-6">
                    <div class="flex items-center mb-4">
                        <div class="w-12 h-12 bg-yellow-100 rounded-lg flex items-center justify-center mr-4">
                            <i class="fas fa-database text-yellow-600 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-gray-800">持久性（Durability）</h3>
                    </div>
                    <p class="text-gray-600">一旦事务提交，所有更改应该永久保存，不受系统崩溃或故障的影响。</p>
                </div>
            </div>
        </section>

        <!-- Challenges -->
        <section class="mb-12">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">
                <i class="fas fa-exclamation-triangle feature-icon mr-3"></i>分布式事务的主要挑战
            </h2>
            
            <div class="highlight-box">
                <div class="space-y-4">
                    <div class="flex items-start">
                        <i class="fas fa-wifi text-purple-600 mt-1 mr-3"></i>
                        <div>
                            <h4 class="font-semibold text-gray-800 mb-1">网络延迟与故障</h4>
                            <p class="text-gray-600">网络故障或延迟可能导致参与事务的各个节点之间的通信失败，从而影响事务的一致性和可靠性。</p>
                        </div>
                    </div>
                    
                    <div class="flex items-start">
                        <i class="fas fa-project-diagram text-purple-600 mt-1 mr-3"></i>
                        <div>
                            <h4 class="font-semibold text-gray-800 mb-1">协调复杂性</h4>
                            <p class="text-gray-600">协调多个服务或数据库的事务操作，确保它们都达到一致状态，增加了事务管理的复杂性。</p>
                        </div>
                    </div>
                    
                    <div class="flex items-start">
                        <i class="fas fa-tachometer-alt text-purple-600 mt-1 mr-3"></i>
                        <div>
                            <h4 class="font-semibold text-gray-800 mb-1">性能开销</h4>
                            <p class="text-gray-600">处理分布式事务通常涉及额外的网络通信和协调开销，这可能对系统性能产生负面影响。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Solutions -->
        <section class="mb-12">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">
                <i class="fas fa-lightbulb feature-icon mr-3"></i>分布式事务的解决方案
            </h2>

            <!-- 2PC -->
            <div class="solution-card mb-6">
                <h3 class="text-2xl font-semibold mb-4 text-gray-800">
                    <i class="fas fa-code-branch text-purple-600 mr-2"></i>两阶段提交协议（2PC）
                </h3>
                
                <p class="text-gray-600 mb-4">两阶段提交协议是分布式事务中最经典的协议，其主要步骤包括：</p>
                
                <div class="mermaid">
                    graph LR
                        A[协调者] -->|准备请求| B[参与者1]
                        A -->|准备请求| C[参与者2]
                        A -->|准备请求| D[参与者3]
                        B -->|准备响应| A
                        C -->|准备响应| A
                        D -->|准备响应| A
                        A -->|提交/回滚| B
                        A -->|提交/回滚| C
                        A -->|提交/回滚| D
                </div>
                
                <div class="pros-cons">
                    <div class="pros">
                        <h4 class="font-semibold text-green-700 mb-2">
                            <i class="fas fa-check mr-1"></i>优点
                        </h4>
                        <p class="text-gray-600">确保事务的原子性和一致性。</p>
                    </div>
                    <div class="cons">
                        <h4 class="font-semibold text-red-700 mb-2">
                            <i class="fas fa-times mr-1"></i>缺点
                        </h4>
                        <ul class="text-gray-600 space-y-1">
                            <li>• 协调过程可能导致系统性能瓶颈</li>
                            <li>• 参与者需要长时间保持锁定状态</li>
                            <li>• 可能出现协调者崩溃导致的协调失败</li>
                        </ul>
                    </div>
                </div>
            </div>

            <!-- 3PC -->
            <div class="solution-card mb-6">
                <h3 class="text-2xl font-semibold mb-4 text-gray-800">
                    <i class="fas fa-layer-group text